package util

import (
	"fmt"
	"strconv"
	"strings"
)

func ToString(vals []interface{}) string {
	sb := new(strings.Builder)
	sb.WriteRune('[')
	for i, v := range vals {
		switch v.(type) {
		case int:
			sb.WriteString(strconv.Itoa(v.(int)))
		case int64:
			sb.WriteString(strconv.FormatInt(v.(int64), 10))
		case byte:
			sb.WriteByte(v.(byte))
		case rune:
			sb.WriteRune(v.(rune))
		case []byte:
			sb.Write(v.([]byte))
		case string:
			sb.WriteString(v.(string))
		case float32:
			sb.WriteString(fmt.Sprintf("%f", v.(float32)))
		case float64:
			sb.WriteString(fmt.Sprintf("%f", v.(float64)))
		case fmt.Stringer:
			sb.WriteString(v.(fmt.Stringer).String())
		default:
			sb.WriteString("<invalid>")
		}
		if i < len(vals)-1 {
			sb.WriteRune(',')
		}
	}
	sb.WriteRune(']')
	return sb.String()
}
